<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>液体动态背景</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }

    #canvas-container {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }

    canvas {
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
<div id="canvas-container"></div>

<script>
  const canvas = document.getElementById('canvas-container').querySelector('canvas');
  const ctx = canvas.getContext('2d');

  const width = canvas.width;
  const height = canvas.height;

  const particleCount = 1000; // 粒子数量
  const particles = [];

  class Particle {
    constructor(x, y, radius, color) {
      this.x = x;
      this.y = y;
      this.radius = radius;
      this.color = color;
      this.vx = Math.random() * 2 - 1; // x 轴方向速度
      this.vy = Math.random() * 2 - 1; // y 轴方向速度
    }

    draw() {
      ctx.beginPath();
      ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
      ctx.fillStyle = this.color;
      ctx.fill();
    }

    update() {
      this.x += this.vx;
      this.y += this.vy;

      // 边界检查
      if (this.x + this.radius > width) {
        this.x = -this.radius;
      } else if (this.x - this.radius < 0) {
        this.x = width + this.radius;
      }

      if (this.y + this.radius > height) {
        this.y = -this.radius;
      } else if (this.y - this.radius < 0) {
        this.y = height + this.radius;
      }
    }
  }

  function init() {
    for (let i = 0; i < particleCount; i++) {
      const radius = Math.random() * 10 + 5; // 粒子大小
      const x = Math.random() * (width - 2 * radius) + radius;
      const y = Math.random() * (height - 2 * radius) + radius;
      const color = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
      const particle = new Particle(x, y, radius, color);
      particles.push(particle);
    }
  }

  function animate() {
    ctx.clearRect(0, 0, width, height);

    for (const particle of particles) {
      particle.draw();
      particle.update();
    }

    requestAnimationFrame(animate);
  }

  init();
  animate();
</script>
</body>
</html>